import request from "@/utils/request";
import type { RoleResponesData, AddRole } from "./type";
enum API {
  //获取所有角色信息
  USERINFO_URL = "/admin/acl/user/",
  //添加角色接口
  ADDUSER_URL = "/admin/acl/user/save",
  //修改角色接口
  UPDATEUSER_URL = "/admin/acl/user/update",
  //根据用户获取角色信息
  GETUSERS_URL = "/admin/acl/user/toAssign/",
  //根据用户添加职位
  SETUSERROLE_URL = "/admin/acl/user/doAssignRole",
  //删除单个用户的接口
  DELETEUSER_URL = "/admin/acl/user/remove/",
  //删除多个用户的id
  DELETEUSERIDS_URL = "/admin/acl/user/batchRemove",
}

export const reqGetUserInfo = (page: number, limit: number, username: string) =>
  request.get<any, any>(
    API.USERINFO_URL + `${page}/${limit}/?username=${username}`,
  );

//修改或者增加用户接口
export const reqAddOrUpdateUser = (data: any) => {
  if (data.id) {
    //修改
    return request.put<any, any>(API.UPDATEUSER_URL, data);
  } else {
    //增加
    return request.post<any, any>(API.ADDUSER_URL, data);
  }
};
//根据用户id获取角色信息
export const reqtoAssign = (adminId: number) =>
  request.get<any, RoleResponesData>(API.GETUSERS_URL + adminId);
//根据用户添加职位
export const reqDoAssignRole = (data: AddRole) =>
  request.post<any, any>(API.SETUSERROLE_URL, data);
//删除单个用户的接口
export const reqDeleteUser = (adminId: number) =>
  request.delete<any, any>(API.DELETEUSER_URL + adminId);
//删除多个用户的id
export const reqDeleteUserIds = (idList: number[]) =>
  request.delete<any, any>(API.DELETEUSERIDS_URL, { data: idList });
